//
//  FKOrderDetailStatusCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKOrderDetailStatusCell.h"
#import "FKOrder.h"

@interface FKOrderDetailStatusCell ()

@property (nonatomic, weak) UILabel *statusNameLabel;
@property (nonatomic, weak) UILabel *statusDescLabel;

@end

@implementation FKOrderDetailStatusCell



- (void)setupSubviews
{
    [super setupSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.clipsToBounds = true;
    self.backgroundColor = fkMainColor;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCountdown:) name:@"" object:nil];
    
    UILabel *statusNameLabel = [UILabel fk_labelWithFont:fk_adjustFont(16) textColor:[UIColor whiteColor]];
    [self.contentView addSubview:statusNameLabel];
    self.statusNameLabel = statusNameLabel;
    
    UILabel *statusDescLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:[UIColor whiteColor]];
    [self.contentView addSubview:statusDescLabel];
    self.statusDescLabel = statusDescLabel;
    
    UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"order_detail_icon"]];
    [self.contentView addSubview:iconView];
    
    [statusNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(fk_adjustW(25));
        make.bottom.equalTo(self.contentView.mas_centerY).offset(-8);
    }];
    [statusDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(statusNameLabel);
        make.right.offset(-12);
        make.top.equalTo(self.contentView.mas_centerY).offset(8);
    }];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(fk_adjustW(48));
        make.right.offset(fk_adjustW(-50));
        make.centerY.offset(0);
    }];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)updateCountdown:(NSNotification *)noti
{
    NSDictionary *dict = noti.userInfo;
    NSInteger countdown = [dict[@"countdown"] integerValue];
    NSInteger miniute = countdown / 60;
    NSInteger second = countdown % 60;
    
    FKOrder *model = self.data;
    if ([model.item_type isEqualToString:@"2"] && [model.status isEqualToString:@"30"]) { // 物流订单待收货状态
        self.statusDescLabel.text = fkFORMAT(@"剩%02zd分%02zd秒确认收货", miniute, second);
    } else {
        self.statusDescLabel.text = fkFORMAT(@"剩%02zd分%02zd秒自动关闭", miniute, second);
    }
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKOrder class]]) {
        FKOrder *model = data;
        self.statusNameLabel.text = model.status_name;
        self.statusDescLabel.text = model.status_title;
    }
}

@end
